<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="活动标题">
              <a-input placeholder="请输入" v-model="queryParam.key"></a-input>
            </a-form-item>
          </a-col>
        
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> -->
      <a-button type="primary" icon="download" @click="handleExportXlsSelf('活动报名')">导出</a-button>
<!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
<!--        <a-button type="primary" icon="import">导入</a-button>-->
<!--      </a-upload>-->
<!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
<!--        <a-menu slot="overlay">-->
<!--          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>-->
<!--        </a-menu>-->
<!--        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
<!--      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a :disabled="record.DataStatus == 1 || record.DataStatus == 2" @click="handleVerifyModal(record)">审批</a>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->
    <ActivityModal ref="modalForm" @ok="modalFormOk"></ActivityModal>
    <!-- 表单区域 -->
  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import pick from 'lodash.pick'
  import { downFile,postAction } from '@/api/manage'
  import ActivityModal from './modules/ActivityModal'
  export default {
    name: "AuthUserList",
    mixins:[JeecgListMixin],
    components: {
        ActivityModal
    },
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        form: this.$form.createForm(this),
        rowObj:{},
        changePasswordModal:false,
        description: '活动报名表',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
           },
		   {
            title: '活动标题',
            align:"center",
            dataIndex: 'EventTitle',
            isKey:true,
            sorter: (a, b) => a.EventTitle - b.EventTitle,
           },
           {
            title: '活动类型',
            align:"center",
            dataIndex: 'EventType',
           },
		   {
            title: '真实姓名',
            align:"center",
            dataIndex: 'UserName',
           },
		   {
            title: '公司',
            align:"center",
            dataIndex: 'CompanyName'
           },
           {
            title: '职务',
            align:"center",
            dataIndex: 'UserInfo_Job'
           },
           // {
           //  title: '职务标签',
           //  align:"center",
           //  dataIndex: 'UserInfo_PositionTag'
           // },
		   {
            title: '手机',
            align:"center",
            dataIndex: 'Phone',
           },
		        {
            title: '微信',
            align:"center",
            dataIndex: 'Wechat'
           },
           {
            title: '邮箱',
            align:"center",
            dataIndex: 'Email'
           },
           {
            title: '报名日期',
            align:"center",
            dataIndex: 'Ts',
            defaultSortOrder: 'descend',
            sorter: (a, b) => a.Ts - b.Ts,
            customRender:function (t,r,index) {
              return t?new Date(parseInt(t)).toLocaleDateString().replace('/','-').replace('/','-'):'';
            }
           },
		        {
            title: '异动日期',
            align:"center",
            dataIndex: 'IntegralTime',
            customRender:function (t,r,index) {
              return t?new Date(parseInt(t)).toLocaleDateString().replace('/','-').replace('/','-'):'';
            }
           },
           {
            title: '审批状态',
            align:"center",
            dataIndex: 'DataStatus',
            customRender:function (t,r,index) {
              return t == '0'?'待审批':t == '1'?'审批通过':t == '2'?'审批驳回':'';
            }
           },
           {
            title: '操作',
            dataIndex: '',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
		url: {
          list: "/userEvent/queryRows",
          delete: "/userEvent/delete",
          deleteBatch: "/robot/authUser/deleteBatch",
          exportXlsUrl: "robot/authUser/exportXls",
          importExcelUrl: "robot/authUser/importExcel",
       },
    }
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
    methods: {
      handleVerifyModal(record){
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.title = "审核";
        sessionStorage.setItem('editType','edit')
        this.$refs.modalForm.disableSubmit = false;
      },
      showChangePassword(record){
        this.rowObj = record;
        this.changePasswordModal = true;
        this.form.resetFields();
        this.$nextTick(() => {
          this.form.setFieldsValue(pick({},'oldPassword','newPassword','newPasswordConfirm'))
        })
      },
      handleExportXlsSelf(fileName){
        let json = {PageIndex:1,PageSize:10000,selectFields:['EventTitle','UserName','CompanyName','Job','Phone','Email'],conditions:[]};
        if(this.queryParam.key){
          json.conditions = [{
            "field":"EventTitle",
            "operator":"like",
            "value":this.queryParam.key
          }]
        }
        downFile('/userEvent/queryRows/excel',json).then(res=>{
          if(res.status == 200){
            let data = res.data;
            if (typeof window.navigator.msSaveBlob !== 'undefined') {
                window.navigator.msSaveBlob(new Blob([data],{type: 'application/vnd.ms-excel'}), fileName+'.xls')
            }else{
                let url = window.URL.createObjectURL(new Blob([data],{type: 'application/vnd.ms-excel'}))
                let link = document.createElement('a')
                link.style.display = 'none'
                link.href = url
                link.setAttribute('download', fileName+'.xls')
                document.body.appendChild(link)
                link.click()
                document.body.removeChild(link); //下载完成移除元素
                window.URL.revokeObjectURL(url); //释放掉blob对象
            }
          }
        })
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>